package com.demo.cloud.server;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    RestTemplate restTemplate;
    @RequestMapping("/send")
    public Object send(String msg, HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("1 client:"+msg);
        int a = request.getContentLength();
        byte[] b = new byte[a];
        request.getInputStream().read(b);
        String s = new String(b);
        System.out.println(s);
        return "[server:"+msg+"]";
    }
    @RequestMapping("/call")
    public Object call(String msg){
        ArrayList result = restTemplate.getForObject("http://client-t/client/test/send?msg="+msg,ArrayList.class);
        return "result:"+result;
    }
}
